package sis.utiltest;/*
* @auther 顶风少年 
* @mail dfsn19970313@foxmail.com
* @date 2019-07-30 10:05
* @notify 
* @version 1.0
*/

import junit.framework.TestCase;
import sis.util.IOUtil;
import sis.util.TestUtil;

import java.io.File;
import java.io.IOException;

public class IOUtilTest extends TestCase {
    static final String FILENAME1 = "IOTUILTest1.txt";

    static final String FILENAME2 = "IOTUILTest2.txt";

    //测试删除
    public void testDeleteSingleFile()throws IOException{
        //创建
        create(FILENAME1);
        //删除
        assertTrue(IOUtil.delete(FILENAME1));
        //如果存在则删除
        TestUtil.assertGone(FILENAME1);
    }

    //删除多个
    public void testDeleteMultipleFiles()throws IOException{
        create(FILENAME1,FILENAME2);
        assertTrue(IOUtil.delete(FILENAME1,FILENAME2));
        TestUtil.assertGone(FILENAME1,FILENAME2);
    }

    //删除不存在的文件
    public void testDeleteNoFile()throws IOException{
        TestUtil.delete(FILENAME1);
        assertFalse(IOUtil.delete(FILENAME1));
    }

    //删除一个存在的一个不存在的
    public void testDeletePartiallySuccessful()throws IOException{
        create(FILENAME1);
        TestUtil.delete(FILENAME2);
        assertFalse(IOUtil.delete(FILENAME1,FILENAME2));
        TestUtil.assertGone(FILENAME1);
    }

    //先删除后创建
    private void create(String ...filenames)throws IOException{
        for(String filename :filenames){
            TestUtil.delete(filename);
            new File(filename).createNewFile();
        }
    }
}
